package be.xios.projectquiz.player;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.JPanel;
import be.xios.projectquiz.game.Game;
import be.xios.projectquiz.global.ScreenMethods;

public class EndPanel extends JPanel {


	private static final long serialVersionUID = -1644869898216668363L;
	private String thema = "White", fontFamily = "Arial",
			gradientSet = "Horizontal";
	private Color customTheme, customFontColor = Color.BLACK;
	private boolean gradient = true, gradientInvert = false;
	private int fontStyle = 1;

	private int sizeX, sizeY;
	private Game currentGame;
	private boolean fullscreen = true;
	
	public EndPanel(Game currentGame) {
		this.currentGame=currentGame;
	}
	
	public void paintComponent(Graphics g) {
		super.paintComponent(g);

		Graphics2D g2D = (Graphics2D) g;
		g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
				RenderingHints.VALUE_ANTIALIAS_ON);
		if (gradient && gradientSet == "Horizontal") {
			if (!gradientInvert) {
				GradientPaint gp = new GradientPaint(getWidth() / 2, 0,
						getBackground().brighter().brighter().brighter(),
						getWidth() / 2, getHeight(), getBackground().darker()
								.darker());
				g2D.setPaint(gp);
				g2D.fillRect(0, 0, getWidth(), getHeight());
			} else {
				GradientPaint gp = new GradientPaint(getWidth() / 2, 0,
						getBackground().darker().darker().darker(),
						getWidth() / 2, getHeight(), getBackground().brighter()
								.brighter());
				g2D.setPaint(gp);
				g2D.fillRect(0, 0, getWidth(), getHeight());
			}
		} else if (gradient && gradientSet == "Vertical") {
			if (!gradientInvert) {
				GradientPaint gp = new GradientPaint(0, getHeight() / 2,
						getBackground().brighter().brighter().brighter(),
						getWidth(), getHeight() / 2, getBackground().darker()
								.darker());
				g2D.setPaint(gp);
				g2D.fillRect(0, 0, getWidth(), getHeight());
			} else {
				GradientPaint gp = new GradientPaint(0, getHeight() / 2,
						getBackground().darker().darker().darker(), getWidth(),
						getHeight() / 2, getBackground().brighter().brighter());
				g2D.setPaint(gp);
				g2D.fillRect(0, 0, getWidth(), getHeight());
			}
		} else {
			g2D.setColor(customTheme);
			g2D.fillRect(0, 0, getWidth(), getHeight());
		}

		if (thema.equals("Orange")) {
			this.setBackground(new Color(227, 58, 7));
			g2D.setColor(new Color(100, 60, 0));
		} else if (thema.equals("Blue")) {
			this.setBackground(new Color(7, 127, 227));
			g2D.setColor(new Color(0, 0, 150));
		} else if (thema.equals("Green")) {
			this.setBackground(new Color(66, 227, 7));
			g2D.setColor(new Color(0, 120, 0));
		} else if (thema.equals("White")) {
			this.setBackground(new Color(194, 194, 194));
			g2D.setColor(new Color(0, 0, 0));
		} else {
			this.setBackground(customTheme);
			g2D.setColor(customFontColor);
		}
		
		if (fullscreen) {
			ScreenMethods main = new ScreenMethods();

			sizeX = main.getFullScreenX();
			sizeY = main.getFullScreenY();
		}
		
		String speltype = currentGame.getGameName();
		
		String []player = new String[currentGame.getSpelers()];

		g2D.setFont(new Font(fontFamily, fontStyle, (int) (0.022 * sizeY)));
		for (int i = 0; i < player.length; i++) {
			if (speltype.equals("BLOKKEN")) {
				player[i] = currentGame.getPlayerList().get(i).getVoornaam();
			} else
			if (speltype.equals("ZAALQUIZ")) {
				player[i] = currentGame.getPlayerList().get(i).getNaam();
			}
			//Score geeft 0, alleen op de EndPanel, gek gek gek gek gek , rage ragEEEEEEEE
			//getPlayerList() geeft ook een klokje op t groene bolletje als ge currentGame.+CTRL-SPATIE doet, wa is da????
			g2D.drawString(player[i] + ": " + currentGame.getPlayerList().get(i).getScore(), (int) (0.01 * sizeX),
					(int) (0.05 * sizeY)*(i+1));
		}
		
		g2D.setFont(new Font(fontFamily, fontStyle, (int) (0.04 * sizeX)));
		g2D.drawString(speltype, (int) (0.40 * sizeX), (int) (0.10 * sizeY));
		
		g2D.setFont(new Font(fontFamily, fontStyle, (int) (0.02 * sizeX)));
		FontMetrics metricsWinnaar = g2D.getFontMetrics();
		g2D.drawString("De winnaar is: ", (int) (0.50 * sizeX)-metricsWinnaar.stringWidth("De winnaar is")/2,
				(int) (0.40 * sizeY));

		g2D.setFont(new Font(fontFamily, fontStyle, (int) (0.042 * sizeY)));
		FontMetrics metricsWinnaarNaam = g2D.getFontMetrics();
		g2D.drawString("Sonny", (int) (0.50 * sizeX)-metricsWinnaarNaam.stringWidth("Sonny")/2,
				(int) (0.50 * sizeY));
		// game.tekenSpel(g2D, this.getWidth(), this.getHeight());
	}

}
